home *** CD-ROM | disk | FTP | other *** search
/ EnigmA Amiga Run 1995 October / EnigmA AMIGA RUN 01 (1995)(G.R. Edizioni)(IT)[!][issue 1995-10][Aminet 7].iso / Aminet / dev / gui / BGUI11c.lha / demos / popwindow.c < prev    next >
C/C++ Source or Header  |  1995-01-05  |  9KB  |  183 lines

  1. ;/* Execute me to compile with DICE V3.0
  2. dcc popwindow.c -proto -mi -ms -mRR -lbgui
  3. quit
  4. */
  5. /*
  6. **         $RCSfile: popwindow.c,v $
  7. **      Description: Simple demonstration of jumping to another screen.
  8. **        Copyright: (C) Copyright 1994 Jaba Development.
  9. **                   (C) Copyright 1994 Jan van den Baard.
  10. **                   All Rights Reserved.
  11. **
  12. **          $Author: jaba $
  13. **        $Revision: 1.2 $
  14. **            $Date: 1994/09/23 11:29:18 $
  15. **/
  16.  
  17. #include <libraries/bgui.h>
  18. #include <libraries/bgui_macros.h>
  19. #include <libraries/gadtools.h>
  20.  
  21. #include <clib/alib_protos.h>
  22.  
  23. #include <proto/exec.h>
  24. #include <proto/bgui.h>
  25. #include <proto/intuition.h>
  26.  
  27. #include <stdio.h>
  28. #include <stdlib.h>
  29. #include <string.h>
  30.  
  31. /*
  32. **      Library base pointer.
  33. **      NOTE: The intuition.library is opened by DICE
  34. **      it's auto-init code.
  35. **/
  36. struct Library                  *BGUIBase;
  37.  
  38. /*
  39. **      Object ID's.
  40. **/
  41. #define ID_QUIT                 1
  42. #define ID_SCREENNAME           2
  43.  
  44. int main( int argc, char *argv[] )
  45. {
  46.         struct Window           *window;
  47.         Object                  *WO_Window, *GO_Quit, *GO_Name;
  48.         UBYTE                    name[ 64 ];
  49.         ULONG                    signal = 0, rc, tmp;
  50.         BOOL                     running = TRUE;
  51.  
  52.         /*
  53.         **      Open the library.
  54.         **/
  55.         if ( BGUIBase = OpenLibrary( BGUINAME, BGUIVERSION )) {
  56.                 /*
  57.                 **      Create the window object.
  58.                 **/
  59.                 WO_Window = WindowObject,
  60.                         WINDOW_Title,           "PopWindow Demo",
  61.                         WINDOW_ScaleWidth,      20,
  62.                         WINDOW_SizeGadget,      FALSE,
  63.                         WINDOW_PubScreenName,   "Workbench",
  64.                         WINDOW_HelpFile,        "S:User-Startup",
  65.                         WINDOW_HelpNode,        "Main",
  66.                         WINDOW_MasterGroup,
  67.                                 VGroupObject, HOffset( 4 ), VOffset( 4 ), Spacing( 4 ),
  68.                                         StartMember, GO_Name =  String( "Screen Name:", "Workbench", 64, ID_SCREENNAME ), EndMember,
  69.                                         StartMember,
  70.                                                 HGroupObject,
  71.                                                         VarSpace( 50 ),
  72.                                                         StartMember, GO_Quit  = KeyButton( "_Quit",  ID_QUIT  ), EndMember,
  73.                                                         VarSpace( 50 ),
  74.                                                 EndObject,
  75.                                         EndMember,
  76.                                 EndObject,
  77.                 EndObject;
  78.  
  79.                 /*
  80.                 **      Object created OK?
  81.                 **/
  82.                 if ( WO_Window ) {
  83.                         /*
  84.                         **      Assign a key to the button.
  85.                         **/
  86.                         tmp = GadgetKey( WO_Window, GO_Quit,  "q" );
  87.                         /*
  88.                         **      OK?
  89.                         **/
  90.                         if ( tmp ) {
  91.                                 /*
  92.                                 **      try to open the window.
  93.                                 **/
  94.                                 if ( window = WindowOpen( WO_Window )) {
  95.                                         /*
  96.                                         **      Obtain it's wait mask.
  97.                                         **/
  98.                                         GetAttr( WINDOW_SigMask, WO_Window, &signal );
  99.                                         /*
  100.                                         **      Event loop...
  101.                                         **/
  102.                                         do {
  103.                                                 Wait( signal );
  104.                                                 /*
  105.                                                 **      Handle events.
  106.                                                 **/
  107.                                                 while (( rc = HandleEvent( WO_Window )) != WMHI_NOMORE ) {
  108.                                                         /*
  109.                                                         **      Evaluate return code.
  110.                                                         **/
  111.                                                         switch ( rc ) {
  112.  
  113.                                                                 case    WMHI_CLOSEWINDOW:
  114.                                                                 case    ID_QUIT:
  115.                                                                         running = FALSE;
  116.                                                                         break;
  117.  
  118.                                                                 case    ID_SCREENNAME:
  119.                                                                         /*
  120.                                                                         **      Obtain screen name.
  121.                                                                         **/
  122.                                                                         GetAttr( STRINGA_TextVal, GO_Name, &tmp );
  123.                                                                         /*
  124.                                                                         **      Save it.
  125.                                                                         **/
  126.                                                                         strcpy( name, ( UBYTE * )tmp );
  127.                                                                         /*
  128.                                                                         **      Close the window.
  129.                                                                         **/
  130.                                                                         WindowClose( WO_Window );
  131.                                                                         /*
  132.                                                                         **      Setup name.
  133.                                                                         **/
  134.                                                                         SetAttrs( WO_Window, WINDOW_PubScreenName, name, TAG_END );
  135.                                                                         /*
  136.                                                                         **      Re-open window.
  137.                                                                         **/
  138.                                                                         if ( window = WindowOpen( WO_Window )) {
  139.                                                                                 /*
  140.                                                                                 **      Re-set signal mask.
  141.                                                                                 **/
  142.                                                                                 signal = 0L;
  143.                                                                                 GetAttr( WINDOW_SigMask, WO_Window, &signal );
  144.                                                                                 /*
  145.                                                                                 **      Show it in the gadget.
  146.                                                                                 **/
  147.                                                                                 SetGadgetAttrs(( struct Gadget * )GO_Name, window, NULL, STRINGA_TextVal, name, TAG_END );
  148.                                                                         } else {
  149.                                                                                 puts( "Can't re-open the window!" );
  150.                                                                                 goto bye;
  151.                                                                         }
  152.                                                                         break;
  153.                                                         }
  154.                                                 }
  155.                                         } while ( running );
  156.                                 } else
  157.                                         puts ( "Could not open the window" );
  158.                         } else
  159.                                 puts( "Could not assign gadget keys" );
  160.                         bye:
  161.                         /*
  162.                         **      Disposing of the window object will
  163.                         **      also close the window if it is
  164.                         **      already opened and it will dispose of
  165.                         **      all objects attached to it.
  166.                         **/
  167.                         DisposeObject( WO_Window );
  168.                 } else
  169.                         puts( "Could not create the window object" );
  170.                 CloseLibrary( BGUIBase );
  171.         } else
  172.                 puts( "Unable to open the bgui.library" );
  173.  
  174.         return( 0 );
  175. }
  176.  
  177. #ifdef _DCC
  178. int wbmain( struct WBStartup *wbs )
  179. {
  180.         return( main( 0, NULL ));
  181. }
  182. #endif
  183.